//
//  PersonCenterViewController.m
//  宜居HD
//
//  Created by 张金国 on 16/4/28.
//  Copyright © 2016年 张金国. All rights reserved.
//

#ifndef kEditBtnBackgroundColor
#define kEditBtnBackgroundColor [UIColor colorWithRed:0.365 green:0.753 blue:0.749 alpha:1.000]
#endif

#ifndef kLoginOutBackgroundColor
#define kLoginOutBackgroundColor [UIColor colorWithRed:0.992 green:0.333 blue:0.306 alpha:1.000]
#endif

#ifndef kBtnTitleBackgroundColor
#define kBtnTitleBackgroundColor [UIColor colorWithRed:0.988 green:1.000 blue:0.996 alpha:1.000]
#endif

#import "PersonCenterViewController.h"
#import "Macro.h"
#import "Masonry.h"
#import "SyncTimer.h"
#import "UIButton+ColorandText.h"
#import "PhotoBrowserView.h"
#import "PhotobrowseCell.h"
#import "AddPhotoCollectionViewCell.h"
#import "UIView+Frame.h"
#import "InfopanelView.h"
#import "LoginViewController.h"
#import "UIAlertControllerUtil.h"
#import "SalerInfoViewModel.h"
#import "UIImageView+WebCache.h"
#import "ChangeSalerHeaderImageViewModel.h"
#import "ChangeSalerPicturViewModel.h"
#import "ChangeSalerInfoViewModel.h"

static NSString *identifier = @"Viewcell";

typedef NS_ENUM(NSUInteger, kCenterImagePathWay){
    kCenterImagePathWayFile = 100,
    kCenterImagePathWayNet = 101
};

@interface PersonCenterViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UITextViewDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,UITextFieldDelegate>
{
    UITextField *textFieldOne;
    UITextField *textFieldTwo;
    UITextField *textFieldThree;
    UITextView  *textView;
}
@property (nonatomic, assign)kCenterImagePathWay kCenterImagePathWay;
/**
 *  头像
 */
@property (nonatomic ,strong)UIImageView *headImageView;
/**
 *  个人照片
 */
@property (nonatomic ,strong)PhotoBrowserView      *photoBrowserView;
/**
 * 个人信息面板
 */
@property (nonatomic ,strong)InfopanelView         *infopanelView;
/**
 *  底部的view，装载2个button
 */
@property (nonatomic ,strong)UIView      *bottomView;
/**
 *  编辑button
 */
@property (nonatomic ,strong)UIButton    *editinformationButton;
/**
 *  退出登录button
 */
@property (nonatomic ,strong)UIButton    *loginoutButton;
/**
 *  照片选择器，设置头像
 */
@property (nonatomic, strong)UIImagePickerController *imagePickerController;
/**
 *  修改头像
 */
@property (nonatomic, strong)UIButton    *pictureSettingButton;
/**
 *  个人相册图片数组
 */
@property (nonatomic, strong)NSMutableArray *photoItemArray;

@property (nonatomic, strong)SalerInfoViewModel *salerInfoViewModel;
@property (nonatomic, strong)ChangeSalerHeaderImageViewModel *changeSalerInfoViewModel;
@property (nonatomic, strong)ChangeSalerPicturViewModel *changeSalerPicturViewModel;
@property (nonatomic, strong)ChangeSalerInfoViewModel *changeInfoViewModel;

@end

@implementation PersonCenterViewController

{
    /**
     *  退出登录提示框
     */
    UIAlertController *_alertController;
    //更改头像方式弹框
    UIAlertController *SelectHeaderImageAlert;
    //判断弹出的本机相册选择器是从哪里来的
    NSInteger tempTag;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self loadNetPersonInfo];
    
}

#pragma mark - LifeCircle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.view.frame = kViewControllerScale;
    [self initMyDataSource];
    [self layoutUI];
    
    textFieldOne = [_infopanelView viewWithTag:101];
    textFieldTwo = [_infopanelView viewWithTag:102];
    textFieldThree = [_infopanelView viewWithTag:103];
    textView = [_infopanelView viewWithTag:106];
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return  _photoItemArray.count;

}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    __weak __typeof__(self) weakSelf = self;
    //添加add按钮到第一个item，并且只有在编辑按钮选中的时候才能创建
    if (indexPath.row == 0 && self.editinformationButton.selected == YES) {
        AddPhotoCollectionViewCell *AddCell = (AddPhotoCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"Add" forIndexPath:indexPath];
        return AddCell;
    } else {
        PhotobrowseCell *photobrowseCell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
        if (_photoItemArray.count != 0) {
            //由于数组中有URL连接和本地图片两种类型，通过判断来给cell赋值
            if ([_photoItemArray[indexPath.row] isKindOfClass:[UIImage class]]) {
                self.changeSalerPicturViewModel.finishPicturBlock = ^{
                    photobrowseCell.photo.image = weakSelf.photoItemArray[indexPath.row];
                };
            } else {
                [photobrowseCell.photo sd_setImageWithURL:[NSURL URLWithString:_photoItemArray[indexPath.row]]];
            }
            
        }
        return photobrowseCell;
    }
    
}

#pragma mark -- <UIImagePickerControllerDelegate>
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo NS_DEPRECATED_IOS(2_0, 3_0)
{
    NSInteger senderTag = tempTag - 1000;
    
    if(senderTag == 0) {
        [self uploadPicturNetWork:image];//上传图片
        [self refreshCollectionItemWithImage:image];
        
    } else {
        [self uploadImageNetWork:image];//上传头像
        __weak __typeof__(self) weakSelf = self;
        self.changeSalerInfoViewModel.finishBlock = ^{
            //头像
            [weakSelf changeHeaderImage:image];
        };
        
    }
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    
}

#pragma mark --UICollectionViewDelegateFlowLayout
//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(110,130);
    
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 5, 0, 5);
}
#pragma mark --UICollectionViewDelegate
//UICollectionView被选中时调用的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    DDLogInfo(@"选择%ld",indexPath.row);
}
//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

#pragma mark - private
- (void)initMyDataSource {
    [self photoItemArray];
#pragma mark -- 注册通知:
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addCollectionViewItem) name:@"AddItem" object:nil];
}

#pragma mark - netWork
//获取个人信息发送请求
- (void)loadNetPersonInfo {
    [self.salerInfoViewModel loadRequest];
}

//修改个人资料
- (void)changeSalerInfoNetWork {
    if (![textFieldOne.text isEqualToString:self.InfoModel.realName] || ![textFieldTwo.text isEqualToString:self.InfoModel.birthday] || ![textFieldThree.text isEqualToString:self.InfoModel.phoneNumber] || ![textView.text isEqualToString:self.InfoModel.description2]) {
        
        long timedate = [SyncTimer standardTimeStringTotimeStamp:textFieldTwo.text];
        NSDictionary *dict = @{@"realName":textFieldOne.text,
                               @"birthday":@(timedate),
                               @"phoneNumber":textFieldThree.text,
                               @"resume":textView.text
                               };
        self.changeInfoViewModel.postObject = dict;
        [self.changeInfoViewModel loadRequest];
    }
    
}

//上传头像发送请求
- (void)uploadImageNetWork:(UIImage *)image {
    self.changeSalerInfoViewModel.uploadImage = image;
    [self.changeSalerInfoViewModel loadRequest];
}

//上传生活照请求
- (void)uploadPicturNetWork:(UIImage *)image {
    self.changeSalerPicturViewModel.uploadImage = image;
    [self.changeSalerPicturViewModel loadRequest];
}

- (void)layoutUI {
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(TweentyOffsetViewMargin);
        make.left.equalTo(self.view.mas_left).offset(TweentyOffsetViewMargin);
        make.height.width.equalTo(@(SCREEN_WIDTH/8.0f));
    }];
    [self.pictureSettingButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.headImageView);
        make.centerY.equalTo(self.headImageView.mas_centerY);
        make.height.equalTo(self.headImageView.mas_height).multipliedBy(1/4.0f);
    }];
    
    
    [self.photoBrowserView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headImageView);
        make.height.equalTo(self.headImageView.mas_height).multipliedBy(1.3);
        make.left.equalTo(self.headImageView.mas_right).offset(TenOffsetViewMargin);
        make.right.equalTo(self.view.mas_right).offset(-SCREEN_WIDTH/8.0f);
    }];
    
    [self.infopanelView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.photoBrowserView.mas_bottom).offset(TenOffsetViewMargin);
        make.left.equalTo(self.photoBrowserView.mas_left);
        make.width.equalTo(self.photoBrowserView.mas_width);
        make.height.equalTo(@(SCREEN_HEIGHT*1.8/3.0f));
    }];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.infopanelView.mas_bottom).offset(TenOffsetViewMargin);
        make.left.equalTo(self.infopanelView.mas_left);
        make.right.equalTo(self.infopanelView.mas_right);
        make.bottom.equalTo(self.view.mas_bottom).offset(-TenOffsetViewMargin);
    }];
    
    [self.editinformationButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomView.mas_top).offset(TweentyOffsetViewMargin);
        make.bottom.equalTo(self.bottomView.mas_bottom).offset(-TweentyOffsetViewMargin);
        make.left.equalTo(self.bottomView.mas_left).offset(TweentyOffsetViewMargin * 2);
        make.width.equalTo(self.bottomView.mas_width).multipliedBy(1.2/3.0f);
    }];
    [self.loginoutButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.editinformationButton.mas_top);
        make.height.equalTo(self.editinformationButton.mas_height);
        make.width.equalTo(self.editinformationButton.mas_width);
        make.right.equalTo(self.bottomView.mas_right).offset(-TweentyOffsetViewMargin * 2);
    }];
    
}


#pragma mark - event response
/**
 *  @author X
 *
 *  添加个人照片跳转事件
 */
- (void)addCollectionViewItem
{
    //切换到相册
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePickerController.delegate = self;
        [imagePickerController setAllowsEditing:NO];
        UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
        tempTag = 1000;
        [popOver presentPopoverFromRect:self.photoBrowserView.collectionView.subviews[0].frame inView:self.photoBrowserView.collectionView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    } else {
        [UIAlertControllerUtil generateInfoControllerWithTitle:nil message:@"Error accessing photo library!"];
    }
}

/**
 *  @author X
 *
 *  更改头像本地相册选择
 */
- (void)addHeaderImagePickerView {
    //切换到相册
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePickerController.delegate = self;
        [imagePickerController setAllowsEditing:NO];
        UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
        self.kCenterImagePathWay = kCenterImagePathWayFile;
        tempTag = 1001;
        [popOver presentPopoverFromRect:self.headImageView.frame inView:self.headImageView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
    } else {
        [UIAlertControllerUtil generateInfoControllerWithTitle:nil message:@"Error accessing photo library!"];
    }
}

/**
 *  @author X
 *
 *  刷新添加cell的图片
 *
 *  @param image 选中的图片
 */
- (void)refreshCollectionItemWithImage:(UIImage *)image
{
    //将相册选择的图片加入数组
    [self.photoItemArray addObject:image];
    [self.photoBrowserView.collectionView reloadData];
}

/**
 *  @author X
 *
 *  更改头像
 */
- (void)changeHeaderImage:(UIImage *)image {
    
//    switch (self.kCenterImagePathWay) {
//        case kCenterImagePathWayFile:
            self.headImageView.image = image;
//            break;
//            
//        default:
//            break;
//    }
}


/**
 *  @author X
 *
 *  添加collection的第一个加号按钮
 */
- (void)addSelectPhotoItem {
    [_photoItemArray insertObject:@"" atIndex:0];
    [self.photoBrowserView.collectionView reloadData];
}

/**
 *  @author X
 *
 *  移除collection的第一个加号按钮
 */
- (void)deleteAddItem {
    [_photoItemArray removeObjectAtIndex:0];
    [self.photoBrowserView.collectionView reloadData];
}

/**
 *  @author X
 *
 *  编辑资料按钮事件
 */
- (void)editHandleButtonEvent:(UIButton *)button {
    if (button.selected == NO) {
        self.pictureSettingButton.hidden = NO;
        self.loginoutButton.selected = YES;
        button.selected = YES;
        [self addSelectPhotoItem];
        [self showTextbodarWidth];
    }else {
        [self changeSalerInfoNetWork];
        
        button.selected = NO;
        self.loginoutButton.selected = NO;
        self.pictureSettingButton.hidden = YES;
        [self deleteAddItem];
        [self hiddenTextBodarWidth];
    }
}

- (void)showTextbodarWidth {
    textFieldOne.layer.borderWidth = 1.0f;
    textFieldOne.layer.borderColor = [UIColor lightGrayColor].CGColor;
    textFieldOne.layer.cornerRadius = 5.0f;
    textFieldTwo.layer.borderWidth = 1.0f;
    textFieldTwo.layer.borderColor = [UIColor lightGrayColor].CGColor;
    textFieldTwo.layer.cornerRadius = 5.0f;
    textFieldThree.layer.borderWidth = 1.0f;
    textFieldThree.layer.borderColor = [UIColor lightGrayColor].CGColor;
    textFieldThree.layer.cornerRadius = 5.0f;
}

- (void)hiddenTextBodarWidth {
    textFieldOne.layer.borderWidth = 0.0f;
    textFieldTwo.layer.borderWidth = 0.0f;
    textFieldThree.layer.borderWidth = 0.0f;
}

/**
 *  @author X
 *
 *  退出登录按钮事件
 */
- (void)loginoutHandleButtonEvent:(UIButton *)button {
    if (button.selected == NO) {
        if (self.editinformationButton.selected != NO) {
            self.editinformationButton.selected = YES;
            button.selected = YES;
        }else {
            [self createAlertController];
        }
    }else {
        self.editinformationButton.selected = NO;
        self.pictureSettingButton.hidden = YES;
        button.selected = NO;
    }
}

- (void)pictureSettingButtonEvent:(UIButton *)button {
    SelectHeaderImageAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
    __weak __typeof__(self) weakSelf = self;
    UIAlertAction *fromCamera = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    UIAlertAction *fromPhotoList = [UIAlertAction actionWithTitle:@"从手机相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [weakSelf selectPhotoFromPhoneList];
    }];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [SelectHeaderImageAlert addAction:fromCamera];
    [SelectHeaderImageAlert addAction:fromPhotoList];
    [SelectHeaderImageAlert addAction:cancelAction];
    
    [self presentViewController:SelectHeaderImageAlert animated:YES completion:nil];
}

/**
 *  @author X
 *
 *  手机相册选择头像
 */
- (void)selectPhotoFromPhoneList {
    [self addHeaderImagePickerView];
}

#pragma mark - Getters
- (UIImageView *)headImageView {
    if (!_headImageView) {
        _headImageView = [[UIImageView alloc]init];
        _headImageView.userInteractionEnabled = YES;
        _headImageView.backgroundColor = [UIColor orangeColor];
        _headImageView.layer.cornerRadius = SCREEN_WIDTH/16.0f;
        _headImageView.clipsToBounds = YES;
        [self.view addSubview:_headImageView];
    }
    return _headImageView;
}
- (PhotoBrowserView *)photoBrowserView {
    if (!_photoBrowserView) {
        _photoBrowserView = [[PhotoBrowserView alloc]init];
        _photoBrowserView.backgroundColor = [UIColor clearColor];
        _photoBrowserView.collectionView.delegate = self;
        _photoBrowserView.collectionView.dataSource = self;
        [_photoBrowserView.collectionView registerClass:[AddPhotoCollectionViewCell class] forCellWithReuseIdentifier:@"Add"];
        [_photoBrowserView.collectionView registerClass:[PhotobrowseCell class] forCellWithReuseIdentifier:identifier];
        [self.view addSubview:_photoBrowserView];
    }
    return _photoBrowserView;
}
- (InfopanelView *)infopanelView {
    if (!_infopanelView) {
        _infopanelView = [[InfopanelView alloc]init];
        [self.view addSubview:_infopanelView];
    }
    return _infopanelView;
}

- (UIView *)bottomView {
    if (!_bottomView) {
        _bottomView = [[UIView alloc]init];
        [self.view addSubview:_bottomView];
    }
    return _bottomView;
}

- (UIButton *)editinformationButton {
    if (!_editinformationButton) {
        _editinformationButton = [UIButton buttonWithBackgroundColor:kEditBtnBackgroundColor textFont:[UIFont preferredFontForTextStyle:UIFontTextStyleTitle3] textColor:kBtnTitleBackgroundColor title:@"编辑个人资料" cornerRadius:5.0f];

        [_editinformationButton setTitle:@"编辑个人资料" forState:UIControlStateNormal];
        [_editinformationButton setTitle:@"保存资料" forState:UIControlStateSelected];
        
        [_editinformationButton addTarget:self action:@selector(editHandleButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self.bottomView addSubview:_editinformationButton];
    }
    return _editinformationButton;

}

- (UIButton *)loginoutButton {
    if (!_loginoutButton) {
        _loginoutButton =  [UIButton buttonWithBackgroundColor:kLoginOutBackgroundColor textFont:[UIFont preferredFontForTextStyle:UIFontTextStyleTitle3] textColor:kBtnTitleBackgroundColor title:@"退出登录" cornerRadius:5.0f];
        
        [_loginoutButton setTitle:@"退出登录" forState:UIControlStateNormal];
        [_loginoutButton setTitle:@"取消修改" forState:UIControlStateSelected];
        
        [_loginoutButton addTarget:self action:@selector(loginoutHandleButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self.bottomView addSubview:_loginoutButton];
    }
    return _loginoutButton;
}

- (UIImagePickerController *)imagePickerController {
    if (!_imagePickerController) {
        _imagePickerController = [[UIImagePickerController alloc]init];
        _imagePickerController.view.backgroundColor = [UIColor orangeColor];
        _imagePickerController.delegate = self;
        _imagePickerController.allowsEditing = YES;
    }
    return _imagePickerController;

}

- (UIButton *)pictureSettingButton {
    if (!_pictureSettingButton) {
        _pictureSettingButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _pictureSettingButton.hidden = YES;
        [_pictureSettingButton setTitle:@"更改头像" forState:UIControlStateNormal];
        _pictureSettingButton.backgroundColor = [UIColor grayColor];
        [self.headImageView addSubview:_pictureSettingButton];
        [_pictureSettingButton addTarget:self action:@selector(pictureSettingButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _pictureSettingButton;

}

- (NSMutableArray *)photoItemArray {
    if (!_photoItemArray) {
        _photoItemArray = [NSMutableArray array];
    }
    return _photoItemArray;
}

- (SalerInfoViewModel *)salerInfoViewModel {
    if (!_salerInfoViewModel) {
        _salerInfoViewModel = [SalerInfoViewModel new];
        _salerInfoViewModel.viewObject = self;
    }
    return _salerInfoViewModel;
}

- (ChangeSalerHeaderImageViewModel *)changeSalerInfoViewModel {
    if (!_changeSalerInfoViewModel) {
        _changeSalerInfoViewModel = [ChangeSalerHeaderImageViewModel new];
        _changeSalerInfoViewModel.viewObject = self;
    }
    return _changeSalerInfoViewModel;
}

- (ChangeSalerPicturViewModel *)changeSalerPicturViewModel {
    if (!_changeSalerPicturViewModel) {
        _changeSalerPicturViewModel = [ChangeSalerPicturViewModel new];
        _changeSalerPicturViewModel.viewObject = self;
    }
    return _changeSalerPicturViewModel;
}

- (ChangeSalerInfoViewModel *)changeInfoViewModel {
    if (!_changeInfoViewModel) {
        _changeInfoViewModel = [ChangeSalerInfoViewModel new];
        _changeInfoViewModel.viewObject = self;
    }
    return _changeInfoViewModel;
}

- (void)createAlertController {
    
        _alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"清除当前帐号和密码" preferredStyle:UIAlertControllerStyleAlert];
        __weak __typeof__(self) weakSelf = self;
        UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            DDLogInfo(@"取消");
            [_alertController dismissViewControllerAnimated:YES completion:nil];
        }];
        UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            DDLogInfo(@"确定");
            
            //在这里做数据清除
            
            [weakSelf presentViewController:[[LoginViewController alloc]init] animated:YES completion:nil];
        }];
        [_alertController addAction:cancleAction];
        [_alertController addAction:sureAction];
        [self presentViewController:_alertController animated:YES completion:nil];

}

#pragma mark - Setter
- (void)setInfoModel:(SalerInfoModel *)InfoModel {
    _InfoModel = InfoModel;
    //text输入框
    NSArray *infoArray = @[InfoModel.account,InfoModel.realName,InfoModel.birthday,InfoModel.phoneNumber,InfoModel.carreerDate,InfoModel.company];
    int i = 0;
    for (UITextField *InfoTextField in self.infopanelView.subviews) {
        if ([InfoTextField isKindOfClass:[UITextField class]]) {
            InfoTextField.text = infoArray[i++];
        }
    }
    //textView
    for (UITextView *InfoTextField in self.infopanelView.subviews) {
        if ([InfoTextField isKindOfClass:[UITextView class]]) {
            InfoTextField.text = InfoModel.description2;
        }
    }
        //头像
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:[kBaseUrl stringByAppendingString:InfoModel.avatar]]];
    
    //照片
    if (InfoModel.images.count != 0) {
        for (int i = 0; i < InfoModel.images.count; i ++) {
            [self.photoItemArray addObject:[kBaseUrl stringByAppendingString:InfoModel.images[i]]];
        }
        [self.photoBrowserView.collectionView reloadData];
    }
}


@end
